package com.example.yiwei.crm.view.activity.JYCoordingActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.BaseActivity;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.data.GetDock;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.view.activity.coordinationActivity.DetailedCoordinationActivity;
import com.example.yiwei.crm.view.activity.jtCustomer.JDcoorActivity;

import org.json.JSONException;
import org.json.JSONObject;

public class DetailedCoordingActivity extends BaseActivity{
    private TextView txt_docking_mechanism,txt_docking_name,txt_docking_department,txt_docking_job,
            txt_phone_number ,txt_adress;
    com.example.yiwei.crm.entity.dockingEntity dockingEntity;
//    private TextView txt_respectful,txt_mail,txt_weibo,txt_zip_code;
    private TextView txt_visit_number,
//        txt_referral_amount,txt_clinical_amount,txt_operation_amount,
        txt_giving_count,txt_manager,txt_create_time,txt_updater,txt_update_time,
            txt_additional,txt_manager_deperment,txt_cname;
    private ImageView img_back,img_delete;
    private String result;
    private ImageView img_luru,img_find,img_update,img_me,img_tj;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detailed_coording);
        img_back= (ImageView) findViewById(R.id.detailed_doc_img_back);
        img_delete= (ImageView) findViewById(R.id.detailed_doc_img_delete1);
        img_tj= (ImageView) findViewById(R.id.item_image_tj);
        img_me= (ImageView) findViewById(R.id.item_image_w);
        img_update= (ImageView) findViewById(R.id.detailed_doc_img_update);
        txt_docking_mechanism= (TextView) findViewById(R.id.dock_detailed_base_txt_docking_mechanism);
        txt_docking_name= (TextView) findViewById(R.id.dock_detailed_base_txt_docking_name);
        txt_docking_department= (TextView) findViewById(R.id.dock_detailed_base_txt_docking_department);
        txt_adress = (TextView) findViewById(R.id.dock_detailed_base_txt_adr);
        txt_docking_job= (TextView) findViewById(R.id.dock_detailed_base_txt_docking_job);
        txt_phone_number= (TextView) findViewById(R.id.dock_detailed_base_txt_phone_number);
        img_find= (ImageView) findViewById(R.id.item_image_cx);
        img_luru= (ImageView) findViewById(R.id.item_image_lr);
//        txt_respectful= (TextView)findViewById(R.id.dock_detailed_main_txt_docking_respectful);
//        txt_mail= (TextView)findViewById(R.id.dock_detailed_main_txt_mail);
//        txt_weibo= (TextView)findViewById(R.id.dock_detailed_main_txt_weibo);
//        txt_zip_code= (TextView) findViewById(R.id.dock_detailed_main_txt_zip_code);

        txt_visit_number= (TextView)findViewById(R.id.dock_detailed_other_txt_visit_number);
//        txt_referral_amount= (TextView) findViewById(R.id.dock_detailed_other_txt_referral_amount);
//        txt_clinical_amount= (TextView) findViewById(R.id.dock_detailed_other_txt_clinical_amount);
//        txt_operation_amount= (TextView)findViewById(R.id.dock_detailed_other_txt_operation_amount);
        txt_giving_count= (TextView) findViewById(R.id.dock_detailed_other_txt_giving_count);
        txt_manager= (TextView) findViewById(R.id.dock_detailed_other_txt_manager);
        txt_manager_deperment = (TextView) findViewById(R.id.dock_detailed_other_txt_manager_dep);
        txt_create_time= (TextView) findViewById(R.id.dock_detailed_other_txt_create_time);
        txt_updater= (TextView) findViewById(R.id.dock_detailed_other_txt_updater);
        txt_update_time= (TextView) findViewById(R.id.dock_detailed_other_txt_update_time);
        txt_additional= (TextView)findViewById(R.id.dock_detailed_other_txt_additional);
        txt_cname = (TextView) findViewById(R.id.dock_detailed_other_txt_cna);
        dockingEntity= GetDock.get();
        txt_docking_mechanism.setText(dockingEntity.getDocking_mechanism());
        txt_docking_name.setText(dockingEntity.getDocking_name());
        txt_docking_department.setText(dockingEntity.getDepartment());
        txt_docking_job.setText(dockingEntity.getProfessional_title());
        txt_phone_number.setText(dockingEntity.getPhone_number());
        txt_adress.setText(dockingEntity.getPname()+dockingEntity.getCname()+dockingEntity.getAname()+ZString(dockingEntity.getJd())+ZString(dockingEntity.getAddress()));
//        txt_respectful.setText(dockingEntity.getRespectfully());
//        txt_mail.setText(dockingEntity.getMail());
//        txt_weibo.setText(dockingEntity.getWeibo());
//        txt_zip_code.setText(dockingEntity.getZip_code());

        txt_manager_deperment.setText(dockingEntity.getManager_department());
        txt_visit_number.setText(dockingEntity.getVisit_number()+"");
//        txt_referral_amount.setText(dockingEntity.getReferral_amount()+"");
//        txt_clinical_amount.setText(dockingEntity.getClinical_amount()+"");
//        txt_operation_amount.setText(dockingEntity.getOperation_amount()+"");
        txt_giving_count.setText(dockingEntity.getGiving_count()+"");
        txt_manager.setText(dockingEntity.getManager());
        txt_create_time.setText(dockingEntity.getCreate_time());
        txt_updater.setText(dockingEntity.getCurrent_update_name());
        txt_update_time.setText(dockingEntity.getUpdate_time());
        txt_additional.setText(dockingEntity.getAddtional_remark());
        txt_cname.setText(dockingEntity.getCurrent_create_name());

        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        img_luru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(DetailedCoordingActivity.this, JDcoorActivity.class);
                startActivity(intent);
                finish();
            }
        });
        img_find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(DetailedCoordingActivity.this, JDcoorActivity.class);
                intent.putExtra("ii","ii");
                startActivity(intent);
                finish();
            }
        });
        img_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(DetailedCoordingActivity.this, JDcoorActivity.class);
                intent.putExtra("me","me");
                startActivity(intent);
                finish();
            }
        });
        img_tj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(DetailedCoordingActivity.this, JDcoorActivity.class);
                intent.putExtra("tt","tt");
                startActivity(intent);
                finish();
            }
        });
        //修改合作客户
        img_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(DetailedCoordingActivity.this,AddCoorActivity.class);
                intent.putExtra("tag","update");
                startActivity(intent);
                finish();
            }
        });
        //删除合作客户
        img_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(new ContextThemeWrapper(DetailedCoordingActivity.this, R.style.custom_dialog));
                builder.setTitle("您确定要删除吗？");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                JSONObject object = new JSONObject();
                                try {
                                    object.put("DEL01", 1);
                                    object.put("KXA01", dockingEntity.getDocking_id());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                String json = object.toString();
                                result = NetWorkUtils.getCount(baseClass.delect_coordianation_URL, json);
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            JSONObject object1 = new JSONObject(result);
                                            boolean b = object1.getBoolean("ifsuccess");
                                            if (b) {
                                                finish();
                                            }
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                });
                            }
                        }).start();
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
                builder.show();
            }
        });

    }
    private String ZString(String str){
        if (str==null){
            return "";
        }
        return str;
    }
}
